#include "stdafx.h"
#include "TextureContainer.h"
#include "Texture.h"

Graphics::TextureContainer::TextureContainer()
{

}

Graphics::TextureContainer::~TextureContainer()
{
	
}

Graphics::Texture* Graphics::TextureContainer::GetTexture(const std::string& aFileName)
{
	std::string key(aFileName);
	Utilities::ToLower(key);

	std::map<std::string, Texture*>::iterator tex = myTextures.find(key);
	if(tex != myTextures.end())
	{
		return tex->second;
	}

	return LoadTexture(key);
}

Graphics::Texture* Graphics::TextureContainer::LoadTexture(const std::string& aFileName)
{
	Texture* tex = new Texture;
	if(tex->Init(GETPATH(aFileName)) == false)
	{
		delete tex;
		tex = NULL;
	}

	myTextures.insert(std::make_pair(aFileName, tex));
	return tex;
}